using Game.XH;
using UnityEngine;

public class MapViewCableCar : MonoBehaviour
{
	private float minX = 300f;

	private float maxX = 2800f;

	private float defaultY;

	private bool moveLeft;

	private float curX;

	private float speed = 50f;

	private bool isDown;

	private float angle;

	private float waitTimer;

	private Transform pole;

	private Transform polePoint;

	private Transform body;

	private void Awake()
	{
		curX = ((RectTransform)base.transform).anchoredPosition.x;
		defaultY = ((RectTransform)base.transform).anchoredPosition.y;
		((RectTransform)base.transform).anchoredPosition = new Vector3(curX, defaultY);
		pole = base.transform.Find("Pole1/Pole2");
		polePoint = pole.Find("Point");
		body = base.transform.Find("Body");
	}

	private void Update()
	{
		if (waitTimer > 0f)
		{
			waitTimer -= Time.deltaTime;
			return;
		}
		if (moveLeft)
		{
			curX -= Time.deltaTime * speed;
			if (curX <= minX)
			{
				curX = minX;
				waitTimer = Random.Range(2, 5);
				moveLeft = !moveLeft;
			}
			((RectTransform)base.transform).anchoredPosition = new Vector3(curX, defaultY);
		}
		else
		{
			curX += Time.deltaTime * speed;
			if (curX >= maxX)
			{
				curX = maxX;
				waitTimer = Random.Range(2, 5);
				moveLeft = !moveLeft;
			}
			((RectTransform)base.transform).anchoredPosition = new Vector3(curX, defaultY);
		}
		if (isDown)
		{
			angle += Time.deltaTime * 10f;
			if (angle >= 8f)
			{
				angle = 8f;
				isDown = !isDown;
			}
		}
		else
		{
			angle -= Time.deltaTime * 10f;
			if (angle <= 0f)
			{
				angle = 0f;
				isDown = !isDown;
			}
		}
		pole.SetLocalRotationZ(angle);
		body.position = polePoint.position + new Vector3(0f, -0.75f, 0f);
	}
}
